package com.zytlifeservice.controller.pay;

import com.qianmi.open.api.ApiException;
import com.zytlifeservice.domain.Result;
import com.zytlifeservice.exception.UserException;
import com.zytlifeservice.service.pay.AirplaneService;
import com.zytlifeservice.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 飞机票控制类
 * Created by Administrator on 2017/6/3.
 */
@RestController
@RequestMapping(value = "/airplane")
public class AirplaneController {
    @Autowired
    private AirplaneService airplaneService;//飞机票业务类


    //查询飞机城市三字码
    @GetMapping(value = "/findAirplaneCity")
    public Result findAirplaneCity() throws ApiException {
        return airplaneService.findAirplaneCity();
    }

    //查询航线信息
    @PostMapping(value = "/findLines")
    public Result findLines(String from, String to, String fromDate, Integer currentPage) throws Exception {
        return airplaneService.findLines(from, to, fromDate, currentPage);
    }


    @PostMapping(value = "/createAlipayOrder")
    public Result createAliPayOrder(Long userId, String contactName, String contactTel,
                                    String date, String seatCode, String from, String to,
                                    String flightNo, String companyCode, String passagers,
                                    String depTime, String arriTime, String dstCityName,
                                    String orgCityName, String totalPayCash, String subject, String itemId) {

        String[] result = airplaneService.createAliPayOrder(userId, contactName, contactTel, date, seatCode,
                from, to, flightNo, companyCode, passagers, depTime,
                arriTime, dstCityName, orgCityName, totalPayCash, subject, itemId);
        if ("success".equals(result[0])) {
            return ResultUtil.success(result[1], "预下单成功");
        } else {
            throw new UserException(result[1], 202);
        }
    }


    @PostMapping(value = "/createWxPayOrder")
    public Result createWxPayOrder(Long userId, String contactName, String contactTel,
                                   String date, String seatCode, String from, String to,
                                   String flightNo, String companyCode, String passagers,
                                   String depTime, String arriTime, String dstCityName,
                                   String orgCityName, String totalPayCash, String subject,
                                   String ip, String itemId) {
        String[] result = airplaneService.createWxOrder(userId, contactName, contactTel, date, seatCode,
                from, to, flightNo, companyCode, passagers, depTime, arriTime,
                dstCityName, orgCityName, totalPayCash, subject, itemId, ip);
        if ("success".equals(result[0])) {
            return ResultUtil.success(result[1], "预下单成功");
        } else {
            throw new UserException(result[1], 202);
        }
    }
}
